<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/common.jspf"%>
<%@ include file="/common/taglibs.jspf"%>
<html lang="en">
<head>
<!-- jquery datatables -->
<link href="${contextPath}/static/widgets/jquery-datatables/css/jquery.dataTables.css" rel="stylesheet" />
<script src="${contextPath }/static/widgets/jquery-datatables/js/jquery.dataTables.min.js"></script>
<script src="${contextPath }/static/widgets/jquery-datatables/js/jquery.dataTables.bootstrap.js"></script>
</head>
<body>
	<!-- quick view -->
    <h:quickview moduleCode="customer"></h:quickview>	
	<!-- toolbar -->
	<div class="toolbar">	
      <button class="btn btn-small btn-primary" onclick="syncData();">
        <i class="icon-refresh"></i>
        <s:message code="cpUser.func.sync" />
      </button>&nbsp;&nbsp;
      <button class="btn btn-small" onclick="inviteData();">
        <i class="icon-user-add"></i>
        <s:message code="cpUser.func.invite" />
      </button>      	
	</div>	
	<!-- datatable -->
	<div>
      <h:quickview-grid table="${table }" var="row" >
         <div class="action-buttons">
           <c:if test="${4 eq row.WECHAT_STATUS}">
             <a href="javascript:;" onclick="rowInvite(${row.USER_ID});"> <i class="icon-user-add"></i></a>&nbsp;&nbsp;
           </c:if>
           <a href="javascript:;" onclick="rowSendMessage(${row.USER_ID});"> <i class="icon-message-plus"></i></a>&nbsp;&nbsp;
           <a href="javascript:;" onclick="rowMessages(${row.USER_ID});"> <i class="icon-notes"></i></a>
		 </div>
      </h:quickview-grid>    
	  <h:pager params="${requestScope[table.dataset] }" formId="datatable"></h:pager>
	</div>
  
	<!--page specific plugin scripts-->
	<script type="text/javascript">
		$(document).ready(function(){				
			$('.datatable').dataTable();	
			
			var checkboxs = $.webtools.checkboxs({
				checkAll: "#checkAll",
				checkItem: ".checkItem"				
			});
		})		
		
		function syncData()
		{
		  bootbox.confirm("<s:message code='cpUser.func.sync.confirm' />", function(result){
				if(result)
				{
					$.webtools.ajax({
						url: "sync.json",
						success: function(reply) {
							
						}
					});					
				}				
		  });		
		}
		
		function inviteData()
		{
		  $.webtools.ajax({
			url: "invite.json",
			success: function(reply) {
				
			}
		  });	
		}
		
		function batchDelete()
		{					
			if($(".checkItem:checked").length<=0)
			{
				$.webtools.notify({
					type: "notice",
					message: "<s:message code='validate.checkone'/>"
				});
				return;
			}
			var ids = $.webtools.getCheckValuesArray(".checkItem");	
		
			bootbox.confirm("<s:message code='common.delete.confirm' />", function(result){
				if(result)
				{
					$.webtools.ajax({
						url: "deleteBatch.json",
						params: {"ids":ids},
						success: function(reply) {
							location.reload();
						}
					});						
				}				
			});		
		}	
				
		function rowDelete(id)
		{			
			bootbox.confirm("<s:message code='common.delete.confirm' />", function(result){
				if(result)
				{
					$.webtools.ajax({
						url: "delete.json",
						params: {"id":id},
						success: function(reply) {
							location.reload();
						}
					});					
				}				
			});			
		}	
		
		function rowInvite(userId)
		{			
			$.webtools.ajax({
				url: "inviteUser.json",
				params: {"userId":userId},
				success: function(reply) {
				}
			});	
		}	
		
		function rowSendMessage(userId)
		{			
			$.webtools.ajax({
				url: "sendMessage.json",
				params: {"userId":userId},
				success: function(reply) {
				}
			});	
		}	
		</script>
</body>
</html>
